package cn.itcast.java.api;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Author itcast
 * Date 2021/10/10 9:32
 * Desc TODO
 */
public class CalendarDemo3 {
    public static void main(String[] args) {
        //获取 Calendar 的实例
        Calendar instance = Calendar.getInstance();
        //获取当前的年、月、日、在一周某一天
        Date time = instance.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTimeStr = sdf.format(time);
        System.out.println(dateTimeStr);

        int hour = instance.get(Calendar.HOUR);
        int minute = instance.get(Calendar.MINUTE);
        int day = instance.get(Calendar.DAY_OF_MONTH);
        //一年12个月，从0个月开始，
        int month = instance.get(Calendar.MONTH) + 1;
        System.out.println(hour+":"+minute+" Month:"+ month +" day:"+day);
        //设置当前的时间
        instance.set(2021,10,10,9,42,15);
        //获取设置的值
        Date setTime = instance.getTime();
        System.out.println(sdf.format(setTime));
    }
}
